#include<stdio.h>
#include<malloc.h>
#include<math.h>

int getdis(int x,int m,int n,unsigned char* s){
int tmp = 0;
int dis = 0;
int a,b;
if(*(s+((int)x/n)*(n+1)+x%n)=='1'){
return 0;
}else{
for(a=0;a<m*n;++a){
tmp = 0;
if(a==x){
continue;
}else{
if(*(s+((int)a/n)*(n+1)+a%n)=='1'){
b = abs(a-x);
tmp = (int)b/n + b%n;
if(dis == 0||dis > tmp){
dis=tmp;
}
}
}
}
}
return dis;
}

int main(){
int m,n,i,q,tmp;
unsigned char* s;
int* r;
scanf("%d %d",&m,&n);
s = (unsigned char*)malloc(sizeof(unsigned char)*m*(n+1));
r = (int*)malloc(sizeof(int)*m*n);
for(i=0;i<m*(n);++i){s[i]=0;r[i]=0;}
for(i=m*(n);i<m*(n+1);++i){s[i]=0;}
for(i=0;i<m;++i){
scanf("%s",s+i*(n+1));
}
for(i=0;i<m*n;++i){
*(r+i) = getdis(i,m,n,s);
}
for(i=0;i<m*n;++i){
printf("%d ",*(r+i));
if((i+1)%n == 0){
printf("\n");
}
}
free(s);
free(r);
return 0;
}